package com.baidu.speech.qr_code.ui.home;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.baidu.speech.qr_code.R;
import com.google.zxing.WriterException;

import java.text.SimpleDateFormat;
import java.util.Date;

public class HomeFragment extends Fragment {
    private TextView tv_dashboard;
    private EditText ed_dashboard;
    private Button bu_dashboard;
    private Context context;
    private Bitmap zxing;
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_home, container, false);
        initview(root);
        return root;
    }
    //控件的初始化
    private void initview(View view) {
        tv_dashboard=view.findViewById(R.id.tv_dashboard);
        ed_dashboard=view.findViewById(R.id.ed_dashboard);
        bu_dashboard=view.findViewById(R.id.bu_dashboard);
        ed_dashboard.setTextIsSelectable(true);
        bu_dashboard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //判断输入款是否为空
                if (ed_dashboard.getText().toString().trim().equals("")){
                    Toast.makeText(getActivity(), "输入框为空！", Toast.LENGTH_SHORT).show();
                }else{
                    //向HomeMainivity传递数据，数据内容为输入框里面的内容
                    String data=ed_dashboard.getText().toString().trim();
                    SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    Date date=new Date(System.currentTimeMillis());
                    Custom_code_Home cuh=new Custom_code_Home();
                    cuh.setTime(simpleDateFormat.format(date));
                    cuh.setEd_srk(data);
                    cuh.save();
                    Toast.makeText(getActivity(), "保存成功", Toast.LENGTH_SHORT).show();
                    Intent intent=new Intent(getActivity(),HomeMainivity.class);
                    intent.putExtra("extra_data",data);
                    startActivity(intent);
                    //_______________________________________________
                }
            }
        });
    }
}